package pwd.allen.password.config;

import pwd.allen.password.ICheckRule;
import pwd.allen.password.PwdCheckProperties;
import pwd.allen.password.SpelCheckRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 *
 * @author lenovo
 * @create 2021-12-12 14:57
 **/
@Configuration
@EnableConfigurationProperties(PwdCheckProperties.class)
@ConditionalOnWebApplication
@Import(PwdCheckConfiguration.class)
public class PwdCheckAutoConfiguration implements WebMvcConfigurer {

    @Autowired
    private PwdCheckProperties properties;

    /**
     * 弱密码验证类
     * @return
     */
    @ConditionalOnMissingBean(ICheckRule.class)
    @Bean
    public ICheckRule spelCheckRule() {
        SpelCheckRule checkRule = new SpelCheckRule();
        checkRule.setConds(properties.getConds());
//        if (properties.getUtilClassType() != null) {
            checkRule.setUtilClassType(properties.getUtilClassType());
//        }
        return checkRule;
    }

}
